package de.tabuma.shopping.controller;

import java.io.*;
import java.lang.reflect.*;
import java.util.logging.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

import de.tabuma.shopping.view.view;
import de.tabuma.lib.*;
import de.tabuma.shopping.entity.*;
import de.tabuma.shopping.logik.*;
/**
 * @author $Author: alefen $
 * @version $Revision: 1.1.1.1.4.1 $
 * @since $Date: 2010/01/13 10:22:52 $
 */
public abstract class controller extends tabumacontroller {

    private static Logger log =  Logger.getLogger(tabumacontroller.class.getName());

    public abstract String getOrderNav();

    public abstract LicensePackageFacade getLicensePackageFacade();

    public abstract String getUrl();

    public abstract List<LicenseType> getLicenseTypeList();

    public abstract List getAssignmentList();
    public abstract Class getAssignmentClass();
    public abstract Field getAssignmentKeyField();
    public abstract Field getAssignmentShowField();
    public abstract String getAssignmentObjectname();
    public abstract Hashtable<Integer,String> getMethodHashtable();

    public controller(String servlet, Hashtable paramter ) {
        super(servlet, paramter);
    }

    public void navigate(ServletContext context, HttpServletRequest request, HttpServletResponse response,PrintWriter out) {

        String nav = request.getParameter(getOrderNav());
        if(nav==null) {
            nav = "" + de.tabuma.shopping.constants.ORDERNAV_NULL;
        }
        int navInt = Integer.valueOf(nav);

        switch(navInt) {
            case de.tabuma.shopping.constants.ORDERNAV_NULL:
                orderOverview orderOverviewController = new orderOverview(this.getServlet(), this.getParameter(), this.getLicensePackageFacade(), this.getLicenseTypeList(),
                        this.getAssignmentClass(), this.getAssignmentKeyField(), this.getAssignmentShowField(), this.getAssignmentList(), this.getAssignmentObjectname(), this.getMethodHashtable());
                log.fine("Giving focus to orderOverviewController.");
                orderOverviewController.navigate(context, request, response, out);
                break;

            case de.tabuma.shopping.constants.ORDERNAV_LICENSEOVERVIEW:
                overviewLicense overviewlicensecontroller = new overviewLicense(this.getServlet(), this.getParameter(), this.getOrderNav());
                log.fine("Giving focus to licenseOverviewController.");
                overviewlicensecontroller.navigate(context, request, response, out);
                break;

            case de.tabuma.shopping.constants.ORDERNAV_DESCRIPTION:
                description descriptioncontroller = new description(this.getServlet(), this.getParameter(), this.getOrderNav(), this.getLicensePackageFacade());
                log.fine("Giving focus to descriptionController.");
                descriptioncontroller.navigate(context, request, response, out);
                break;

            case de.tabuma.shopping.constants.ORDERNAV_PACKAGE:
                licensePackageOverview licensepackagecontroller = new licensePackageOverview(this.getServlet(), this.getParameter(), this.getOrderNav(), getLicensePackageFacade());
                log.fine("Giving focus to licensePackageController.");
                licensepackagecontroller.navigate(context, request, response, out);
                break;

            case de.tabuma.shopping.constants.ORDERNAV_LICENSEAGREEMENT:
                licenseAgreement licenseagreementcontroller = new licenseAgreement(this.getServlet(), this.getParameter(), this.getOrderNav(), this.getUrl(), getLicensePackageFacade());
                log.fine("Giving focus to licenseAgreementController.");
                licenseagreementcontroller.navigate(context, request, response, out);
                break;

            case de.tabuma.shopping.constants.ORDERNAV_DETAILS:
                details detailscontroller = new details(this.getServlet(), this.getParameter(), this.getOrderNav(), this.getUrl(), this.getLicensePackageFacade());
                log.fine("Giving focus to detailsController.");
                detailscontroller.navigate(context, request, response, out);
                break;

            case de.tabuma.shopping.constants.ORDERNAV_ERRORPAYMENT:
                errorPaymentProcess errorPaymentProcessController = new errorPaymentProcess(this.getServlet(), this.getParameter(), this.getOrderNav());
                log.fine("Giving focus to errorPaymentProcessController.");
                errorPaymentProcessController.navigate(context, request, response, out);
                break;
            case de.tabuma.shopping.constants.ORDERNAV_VERIFICATIONPAYMENT:
                verificationOfPaymentController verificationOfPaymentController = new verificationOfPaymentController(this.getServlet(), this.getParameter(), this.getOrderNav(), this.getLicensePackageFacade());
                log.fine("Giving focus to verificationOfPaymentController.");
                verificationOfPaymentController.navigate(context,request,response, out);
                break;
            case de.tabuma.shopping.constants.ORDERNAV_FORWARDPAYPAL:
                forwardToPayPal forwardToPayPalController = new forwardToPayPal(this.getServlet(), this.getParameter(), this.getOrderNav());
                log.fine("Giving focus to forwardToPayPalController.");
                forwardToPayPalController.navigate(context, request, response, out);
                break;
        }

        view orders = new view(this.getServlet(), this.getParameter(), this.getOrderNav(), this);
        orders.processRequest(context, request, response, out);
    }

    abstract public String getValueFromProperties(String key);
}